package com.xyh.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import sun.rmi.log.LogInputStream;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:kyle
 * @Date:2020/12/25 - 10:08
 * @Project:springboot
 * @Package:com.xyh.springboot.controller
 * @Version:1.0
 */
@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String helloController(ModelMap modelMap){

        modelMap.addAttribute("hello","大家好！我是大熊。");
        System.out.println("HelloController.helloController");
        return "hello";
    }

    @RequestMapping("/hello1")
    public String hello(HttpServletRequest request){

        request.setAttribute("hello","helloSpringBoot");
        return "hello";
    }

    @RequestMapping("/hello2")
    public ModelAndView helloSpringBoot(ModelAndView modelAndView){
        List<String> list = new ArrayList<>();
        list.add("熊大");
        list.add("熊二");
        list.add("光头强");
        modelAndView.setViewName("hello");
        modelAndView.addObject("list",list);
        return modelAndView;
    }
}
